import {observable, action} from 'mobx';
 
export default class Store {
    // 被观察者
    @observable displayNum;
    @observable lastDisplayNum;
    @observable cal;
    
    constructor(props) {
        this.displayNum = '0';
        this.lastDisplayNum = null;
        this.cal = {
            "+": false,
            "-": false,
            "x": false,
            "÷": false,
            "=": false
          };
    }

    @action.bound inputNumberAction(numStr) {
        let displayNum = '';
        if (this.displayNum !== '0') {
            displayNum = this.displayNum;
        }
        for (let key in this.cal){
            if (this.cal[key] && !this.lastDisplayNum){
            if (key !== '='){
                this.lastDisplayNum = this.displayNum;
            }
            displayNum = ''
            break;
            }
        }
        if (displayNum.length >= 10){
            return;
        }
        this.displayNum = displayNum + numStr;
    }
    
}